# coding=utf8
# 全世界最帅的帅哥
from flask_restful import Resource, reqparse
from comment.modules.product import Product
from comment.modules.product_rate import ProductRate
from .serializer import ProductListSerializer, ProductRateListSerializer


class InvestProduct(Resource):
    """
    理财产品资源类
    """

    def get(self):
        # 返回所有的理财产品列表
        prodict_list = Product.query.all()
        data = ProductListSerializer(prodict_list).to_dict()

        return {"msg": "success!", "data": data}


class ProductRateResource(Resource):
    """
    产品利率资源类
    """

    def get(self):
        # 返回一个产品的多个利率列表
        rp = reqparse.RequestParser()
        rp.add_argument("proId", required=True)
        args = rp.parse_args()
        pro_id = args.proId
        rate_list = ProductRate.query.filter(ProductRate.productId == int(pro_id)).all()
        data = ProductRateListSerializer(rate_list).to_dict()

        return {"msg": "success!", "data": data}